<template>
  <div class="func-comp-form">

    <ComponentGlobalSettingForm :id="id" :compConfigData="compConfigData"></ComponentGlobalSettingForm>

    <Tabs name="main_tabs" size="small" v-model="mainTabsValue">
      <TabPane name="main_tab" tab="main_tabs" label="主配置">

        <Form :label-width="120">
          <FormItem label="选择类型">
            <Select :transfer="true" size="small" v-model="type">
              <Option v-for="item in types" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>
          <FormItem label="占位文本">
            <Input size="small" v-model="placeholder" placeholder=""/>
          </FormItem>
          <FormItem label="时间格式">
            <Input size="small" v-model="format" placeholder=""/>
          </FormItem>
          <FormItem label="尺寸">
            <Select :transfer="true" size="small" v-model="size">
              <Option v-for="item in sizes" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>
          <FormItem label="默认值">
            <Input size="small" v-model="defaultValue"/>
          </FormItem>
          <FormItem label="显示底部控制栏">
            <i-switch v-model="confirm"></i-switch>
          </FormItem>
          <FormItem label="显示清空按钮">
            <i-switch v-model="clearable"></i-switch>
          </FormItem>
          <FormItem label="是否可手动输入">
            <i-switch v-model="editable"></i-switch>
          </FormItem>
          <FormItemPanel title="样式配置">
            <FormItem label="放大倍率">
              <Tooltip content="可将组件进行等比例放大" placement="left">
                <InputNumber size="small" :max="10" :min="0" :step="0.1" v-model="inputStyle.scaleValue" :active-change="false"></InputNumber> 倍
              </Tooltip>
            </FormItem>
            <FormItem label="宽度">
              <Input size="small" v-model="inputStyle.width"/>
            </FormItem>
            <FormItem label="背景色">
              <PnColorPicker size="small" v-model="inputStyle.backgroundColor" alpha recommend/>
            </FormItem>
            <FormItem label="文本色">
              <PnColorPicker size="small" v-model="inputStyle.color" alpha recommend/>
            </FormItem>
            <FormItem label="边框颜色">
              <PnColorPicker size="small" v-model="inputStyle.borderColor" alpha recommend/>
            </FormItem>
          </FormItemPanel>
        </Form>

      </TabPane>
      <TabPane name="interaction_tab" tab="main_tabs" label="交互">
        <Container v-if="mainTabsValue == 'interaction_tab'">
          <CustomJsDocument></CustomJsDocument>
          <FormItemPanel title="初始化运行脚本">
            <CodeEditor v-model="customGlobalJsCode"></CodeEditor>
          </FormItemPanel>

          <FormItemPanel title="选中值变化时触发">
            <Alert show-icon style="padding-right: 10px; text-align: justify;">
              时间选择组件中，每选择时、分、秒都会触发一次此事件，如果想要选择完成后点击确认再触发确认事件，可以打开组件的显示底部控制栏，在点击确定按钮时触发中进行确认逻辑处理
            </Alert>
            <InteractionSender :interactionKey="'itemChange'" :canAddFieldsMap="false"></InteractionSender>
            <Alert show-icon>通过value可获取选中值</Alert>
            <CodeEditor v-model="onChangeCode"></CodeEditor>
          </FormItemPanel>

          <FormItemPanel title="点击确定按钮时触发">
            <InteractionSender :interactionKey="'itemOk'" :canAddFieldsMap="false"></InteractionSender>
            <Alert show-icon>通过value可获取选中值</Alert>
            <CodeEditor v-model="onOkCode"></CodeEditor>
          </FormItemPanel>
        </Container>
      </TabPane>
    </Tabs>

  </div>
</template>

<script>

  import FuncCompFormMixin from '@/mixin/FuncCompFormMixin'

  import { createHelpers } from 'vuex-map-fields';

  const { mapFields } = createHelpers({
    getterType: 'designer/getLayoutItem',
    mutationType: 'designer/updateLayoutItem',
  });

  export default {
    name: 'TimePickerCompForm', // 此名称必须填写，且必须与组件文件名相同，并且必须加上Form字符
    mixins: [FuncCompFormMixin],
    data() {
      return {
        types: [
          {label: '单个时间', value: 'time'},
          {label: '时间范围', value: 'timerange'}
        ],
        sizes: [
          {label: '默认', value: 'default'},
          {label: '小尺寸', value: 'small'},
          {label: '大尺寸', value: 'large'},
        ]
      }
    },
    mounted() {

    },
    methods: {},
    computed: {
      ...mapFields({

        type: 'component.compConfigData.type',
        size: 'component.compConfigData.size',
        confirm: 'component.compConfigData.confirm',
        clearable: 'component.compConfigData.clearable',
        editable: 'component.compConfigData.editable',
        placeholder: 'component.compConfigData.placeholder',
        format: 'component.compConfigData.format',
        defaultValue: 'component.compConfigData.defaultValue',

        inputStyle: 'component.compConfigData.inputStyle',
        onChangeCode: 'component.compConfigData.onChangeCode',
        onOkCode: 'component.compConfigData.onOkCode'

      })
    }
  }
</script>

<style scoped>

</style>
